package org.df.ulab.bot.plugins.pmi.command;

import org.df.ulab.bot.api.command.CommandFactory;
import org.df.ulab.bot.api.command.InitializationRequired;
import org.df.ulab.bot.api.message.ImMessage;
import org.df.ulab.bot.api.pmi.entity.Issue;
import org.df.ulab.bot.plugins.pmi.HandlerSession;
import org.df.ulab.bot.plugins.pmi.commons.UserSettings;
import org.df.ulab.bot.util.command.InternetCommand;
import org.df.ulab.bot.util.message.BasicMsgInterpreter;

/**
 * @author Daniel Filgueiras
 * @since 19/06/2011
 */
@CommandFactory(BasicMsgInterpreter.class)
@InitializationRequired
public class StartWork extends InternetCommand {

	private String issueId;
	
	@Override
	public boolean proccess(ImMessage message) {
		int issueNumber = Integer.parseInt(issueId);
		
		Issue issue = HandlerSession.getDatabase().getIssue(issueNumber);
		
		if (issue != null) {
			UserSettings settings = HandlerSession.getUserSettings(remoteId);
			settings.setWorkingIssue(issueNumber);
			settings.setWorkingStartTime(System.currentTimeMillis());
			settings.setWorkedTime(0);
			
			StringBuilder builder =	new StringBuilder()
					.append("Accepted. Issue: *\"")
					.append(issue.getSummary())
					.append("\"*\r\n")
					.append("Check your working time: \"Worked time?\"");
			
			service.reply(message, builder);
		} else {
			service.reply(message, "Unknown issue");
		}

		return true;
	}
	

}
